import 'dart:ui';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_jd/pages/user/user_info/controller.dart';
import 'package:flutter_jd/ui/widgets/body/top_bar.dart';
import 'package:flutter_jd/ui/widgets/kit.dart';
import 'package:get/get_state_manager/get_state_manager.dart';
import 'package:get/route_manager.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

// 个人信息
class UserInfo extends GetView<UserInfoController> {
  @override
  Widget build(BuildContext context) {
    Get.put(UserInfoController());

    return Scaffold(
      appBar: TopBar(
        title: '个人信息',
        isBack: true,
      ),
      body: SingleChildScrollView(
        child: Column(
          children: [
            _buildHead(),
            _buildCard(controller.cardList),
          ],
        ),
      ),
    );
  }

  Widget _buildHead() {
    return Container(
      padding: EdgeInsets.only(
        top: 20.h,
        left: 12.w,
        right: 12.w,
        bottom: 15.h,
      ),
      decoration: BoxDecoration(
        color: Colors.white,
      ),
      child: Column(
        children: [
          Row(
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Text(
                '头像',
                style: TextStyle(fontSize: 15.sp),
              ),
              Row(
                children: [
                  Container(
                    width: 50.r,
                    height: 50.r,
                    decoration: BoxDecoration(
                      color: Color(0xFFF5F5F5),
                      borderRadius: BorderRadius.circular(50.r),
                    ),
                    child: ClipRRect(
                      borderRadius: BorderRadius.circular(50.r),
                      child: Image.asset(
                        'assets/images/common/avatar.png',
                        fit: BoxFit.cover,
                      ),
                    ),
                  ),
                  Kit.iconFont(0xe7e7, Color(0xFF888888), 16.sp)
                ],
              )
            ],
          ),
        ],
      ),
    );
  }

  Widget _buildCard(List list) {
    return Container(
      decoration: BoxDecoration(
        color: Colors.white,
        border: Border(top: BorderSide(color: Color(0xFFF8F8F8))),
      ),
      child: Column(
        children: List.generate(
          list.length,
          (index) => GestureDetector(
            onTap: () {
              String page = list[index]['page'];

              if (page != '') {
                Get.toNamed(page);
              }
            },
            child: Container(
              height: 50.h,
              padding: EdgeInsets.only(left: 12.w, right: 12.w),
              decoration: BoxDecoration(
                border: Border(
                  bottom: BorderSide(
                    color: list.length != index
                        ? Color(0xFFF8F8F8)
                        : Colors.transparent,
                    width: 1,
                  ),
                ),
              ),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text(
                    list[index]['key'],
                    style: TextStyle(fontSize: 15.sp),
                  ),
                  Row(
                    children: [
                      Text(
                        list[index]['value'],
                        style: TextStyle(
                          color: Color(0xFF999999),
                          fontSize: 13.sp,
                        ),
                      ),
                      SizedBox(
                        width: 5.w,
                      ),
                      Kit.iconFont(0xe7e7, Color(0xFF888888), 14.sp)
                    ],
                  ),
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
}
